// pages/liuyan/liuyan.js
import {
    get_pl_list,
    push_pl,
    reply_pl,
    get_show,
    getLikeStatus,
    deleteComment,
    deleteReply,
    getReplyList,
    deleteMessage
} from '../../api/shool/get_score.js';

import util from "../../utils/util.js";
import watch from "../../utils/watch.js";
import Dialog from '../../miniprogram_npm/@vant/weapp/dialog/dialog';
const app = getApp()
let animationShowHeight = 300;
Page({

    /**
     * 页面的初始数据
     */
    data: {
        if_adim: wx.getStorageSync('user'),

        huifu_data: null,
        replyListSize: 1,
        message: '',
        message_id: '',
        num_if: false,
        index: null,
        num: 2,

        pl_values: [],
        emol_index: 0,
        is_emol: false,
        text_type: 'false',
        is_foot: true,
        type: 'NEW',
        w: 0,
        pl_type: null,
        list: {
            page: 1,
        },
        emol_textlist: [],

        huifu_id: null,
        huifu_page: 1,
        huifu_size: 2,
        huifu_height: '',
    },


    //根据index自动滚动到指定位置
    scrollToViewFn(e) {
        //根据id滚动到指定位置
        wx.pageScrollTo({
            scrollTop: 400,
            duration: 1000
        })

    },


    //获取回复列表高度
    getHeight: function (e) {
        var that = this;
        //     setTimeout(() => {
        // 
        //           

        //     },3000)

        setTimeout(() => {
            var query = wx.createSelectorQuery();
            query.select('.hhfdsfdsf').boundingClientRect()

            query.exec(function (res) {

                that.setData({
                    huifu_height: res[0].height
                })

            })
        }, 3000)

    },


    //监听器
    watch: {
        'huifu_id': function (value, oldvalue) {
            if (value != oldvalue) {
                // this.setData({
                //     huifu_page: 1,
                //     huifu_size: 2,

                // })
                this.data.get_huifu_list_1 = this.get_huifu_list()
            }
        }
    },

    //删除评论
    del_pl: function (e) {
        let pages = getCurrentPages(); // 当前页的数据
        let prevPage = pages[pages.length - 2]; // 上一页的数据

        var index = e.currentTarget.dataset.index_1;
        Dialog.confirm({
                title: '提示',
                message: '确定要删除您的这条评论吗？',
            })
            .then(() => {

                deleteComment({
                    openId: wx.getStorageSync('openid'),
                    commentId: e.currentTarget.dataset.value.id
                }).then(res => {
                    if (res.statusCode == 200) {


                        //更新上一级页面的数据
                        prevPage.data.pl_data[this.data.index].replyCount--
                        prevPage.setData({
                            pl_data: prevPage.data.pl_data,
                        })
                        wx.showToast({
                            title: '删除成功',
                            icon: 'success',
                            duration: 1000
                        })
                        //删除列表
                        this.data.pl_values.splice(index, 1);

                        this.setData({
                            pl_values: this.data.pl_values,
                        })
                    } else {
                        wx.showToast({
                            title: '删除失败',
                            icon: 'none',
                            duration: 1000
                        })

                    }

                })
            })
            .catch(() => {
                // on cancel
            });


    },

    //删除回复
    del_huifu: function (e) {
        this.scrollToViewFn()

        let index = e.currentTarget.dataset.index_1;
        let index_1 = e.currentTarget.dataset.index_2;
        Dialog.confirm({
                title: '提示',
                message: '确定要删除您的这条回复吗？',
            })
            .then(() => {


                deleteReply({
                    openId: wx.getStorageSync('openid'),
                    replyId: e.currentTarget.dataset.pl_value.id_1,
                    commentId: e.currentTarget.dataset.pl_value.id
                }).then(res => {
                    if (res.statusCode == 200) {
                        wx.showToast({
                            title: '删除成功',
                            icon: 'success',
                            duration: 1000
                        })
                        //删除列表
                        this.data.pl_values[index].replies.splice(index_1, 1);

                        this.setData({
                            pl_values: this.data.pl_values,
                        })
                    } else {
                        wx.showToast({
                            title: '删除失败',
                            icon: 'none',
                            duration: 1000
                        })
                        this.data.pl_values[index].replies.splice(index_1, 1);

                        this.setData({
                            pl_values: this.data.pl_values,
                        })

                    }

                })
            })
            .catch(() => {
                // on cancel
            });

    },


    //点击关闭遮罩层
    onClickHide() {
        this.setData({
            text_type: "false",
            emol_open_is: 'false'
        })
    },
    //发送评论
    send_pl: function (e) {
        let pages = getCurrentPages(); // 当前页的数据
        let prevPage = pages[pages.length - 2]; // 上一页的数据
        if (e.detail.type == '1') {


            let message = null
            let url = null
            if (this.data.pl_type == '3') {
                this.reply_pl(e.detail)
                message = '回复了你的评论'
                url = "&pl_id=" + e.detail.commentId + "&list=" + JSON.stringify(this.data.list)

            } else {
                this.push_pl(e.detail)
                prevPage.data.pl_data[this.data.index].replyCount++
                prevPage.setData({
                    pl_data: prevPage.data.pl_data,
                })
                message = '评论了你的留言'

                url = "&pl_id=" + e.detail.belongId + "&list=" + JSON.stringify(this.data.list)
            }



            let data = {
                access_token: "accwss_token",
                touser: this.data.sendopenid,
                template_id: "A2xUwOpJv6EJWXd9alXNG964WlB7IMrVAT9kY9oc_M8",
                page: "pages/liuyan_xq/liuyan_xq?openid=" + wx.getStorageSync('openid') + url,
                miniprogram_state: "trial",
                lang: "zh_CN",
                data: {
                    name1: {
                        value: this.uncodeUtf16(e.detail.nickName || e.detail.fromUserNickname)
                    },
                    thing2: {
                        value: "FFLOVE"
                    },
                    thing3: {
                        value: message
                    },
                    date4: {
                        //当前时间
                        value: util.formatTime(new Date())

                    }
                }
            }
            if (this.data.sendopenid != wx.getStorageSync('openid')) {
                this.app.send_message(data)
            }

        } else {

        }
        this.setData({
            text_type: 'false'
        })
    },
    //发送评论
    push_pl(data) {
        push_pl(data).then(res => {

            if (res.statusCode == 200) {
                wx.showToast({
                    title: '评论成功',
                    icon: 'success',
                    duration: 2000
                })
                this.setData({
                    text_type: 'false'
                })

                let time = util.formatTime_1(new Date())
                data.content = JSON.parse(data.content)
                data.nickname = this.uncodeUtf16(data.nickName)
                data.date = time
                data.love_type = false
                data.unlove_type = false
                data.ip = 0
                data.id = res.data.data
                data.replies = []

                this.data.pl_values.unshift(data)

                this.setData({
                    pl_values: this.data.pl_values
                })





            }
        })

        // let data_1 = {
        //     access_token: "accwss_token",
        //     touser: this.data.list.retweets,
        //     template_id: "A2xUwOpJv6EJWXd9alXNG964WlB7IMrVAT9kY9oc_M8",
        //     page: "/pages/index/index",
        //     miniprogram_state: "formal",
        //     lang: "zh_CN",
        //     data: {
        //         name1: {
        //             value: this.data.wx_info.nickName
        //         },
        //         thing2: {
        //             value: "FFLOVE"
        //         },
        //         thing3: {
        //             value: '评论了你的留言'
        //         },
        //         date4: {
        //             //当前时间
        //             value: util.formatTime(new Date())

        //         }
        //     }
        // }

        // this.app.send_message(data_1)
    },

    //回复评论
    huifu(e) {

        let value = e.currentTarget.dataset.pl_value
        let index = e.currentTarget.dataset.index_1

        this.data.huifu_data = {
            value: value,
            index: index
        }


        this.data.sendopenid = value.userId || value.fromUserId

        this.data.pl_type = '3'



        this.setData({

            text_type: 'true',
            pl_type: '3',
            ly_pl_data: value
        })

    },

    //回复评论
    reply_pl(data) {
        reply_pl(data).then(res => {
            if (res.statusCode == 200) {
                //消息提示回复成功
                wx.showToast({
                    title: '回复成功',
                    icon: 'success',
                    duration: 2000
                })

                //获取当前时间
                let time = util.formatTime_1(new Date())
                data.content = JSON.parse(data.content)
                data.fromUserNickname = this.uncodeUtf16(data.fromUserNickname)
                data.toUserNickname = this.uncodeUtf16(data.toUserNickname)
                data.date = time
                data.love_type = false
                data.unlove_type = false
                data.ip = 0
                data.id_1 = res.data.data


                // this.data.pl_values[this.data.huifu_data.index].replyCount++



                //更新评论列表
                //   let arr=this.huifu()
                //     
                this.data.pl_values[this.data.huifu_data.index].replies.push(data)

                this.setData({
                    text_type: 'false',
                    pl_values: this.data.pl_values
                })



            }
        })
    },
    //获取评论点赞状态
    async get_dianzan_status(id) {

        let type = await getLikeStatus({
            "openId": wx.getStorageSync('openid'),
            "type": "0",
            "typeMessageId": [id]
        })

        return type
    },


    //获取评论
    get_pl_list(page, size, replyListSize, type, index) {

        get_pl_list({
            "belongId": this.data.list.id,
            "page": page,
            "pageSize": size,
            "replyListSize": replyListSize
        }).then(res => {
            if (type == '1') {

                this.put_pl_list(res, replyListSize)
            } else {



                //替换评论列表
                this.set_pl_list(res, replyListSize, index)
            }

            wx.stopPullDownRefresh()
        })
    },

    //加工评论
    put_pl_list(res, replyListSize) {


        // this.data.pl_values = res.data.data

        let type = null
        res.data.data.list.forEach(async item => {
            item.replyCount = item.replyCount - replyListSize
            item.nickname = this.uncodeUtf16(item.nickname)
            item.content = JSON.parse(item.content)
            item.num = item.replyCount

            let if_love = await this.get_dianzan_status(item.id)
            console.log(if_love.data.data[0])
            let type = if_love.data.data[0]

            if (type == 'null') {
                item.love_type = false
                item.unlove_type = false
            } else if (type == 'false') {
                item.love_type = false
                item.unlove_type = true
            } else {
                item.love_type = true
                item.unlove_type = false
            }
            //     })
            if (item.replies.length == 1 && item.replies[0].fromUserAvatar == null) {
                item.replies = []
            } else {

                item.replies.forEach(async item_1 => {
                    item_1.date = util.formatTime_1(new Date(item_1.date))
                    item_1.fromUserNickname = this.uncodeUtf16(item_1.fromUserNickname)
                    item_1.toUserNickname = this.uncodeUtf16(item_1.toUserNickname)
                    item_1.content = JSON.parse(item_1.content)
                    item_1.id_1 = item_1.id
                    item_1.id = item.id
                    item_1.ifPublic = 0

                    let if_love = await this.get_dianzan_status( item_1.id_1)
                    console.log(if_love.data.data[0])
                    let type = if_love.data.data[0]

                    if (type == 'null') {
                        item_1.love_type = false
                        item_1.unlove_type = false
                    } else if (type == 'false') {
                        item_1.love_type = false
                        item_1.unlove_type = true
                    } else {
                        item_1.love_type = true
                        item_1.unlove_type = false
                    }

                })
                

                    item.replies = this.deteleObject(item.replies)

               




            }

            item.date = util.formatTime_1(new Date(item.date))
        })

        // setTimeout(() => {
            res.data.data.list.forEach(async item => {
              await  this.data.pl_values.push(item)
            })
        // }, 500) 
        setTimeout(() => {
            this.setData({
                pl_values: this.deteleObject(this.data.pl_values)
            })
        }, 800)


    },

    //替换评论列表
    set_pl_list(res, replyListSize, index) {
        let type = null
        res.data.data.forEach(async item => {
            item.replyCount = item.replyCount - replyListSize
            item.nickname = this.uncodeUtf16(item.nickname)
            item.content = JSON.parse(item.content)

            let if_love = await this.get_dianzan_status(item.id)
            console.log(if_love.data.data[0])
            let type = if_love.data.data[0]

            if (type == 'null') {
                item.love_type = false
                item.unlove_type = false
            } else if (type == 'false') {
                item.love_type = false
                item.unlove_type = true
            } else {
                item.love_type = true
                item.unlove_type = false
            }
            if (item.replies.length == 1 && item.replies[0].fromUserAvatar == null) {
                item.replies = []
            } else {

                item.replies.forEach(async item_1 => {
                    item_1.fromUserNickname = this.uncodeUtf16(item_1.fromUserNickname)
                    item_1.toUserNickname = this.uncodeUtf16(item_1.toUserNickname)
                    item_1.content = JSON.parse(item_1.content)
                    item_1.id_1 = item_1.id
                    item_1.id = item.id

                    let if_love = await this.get_dianzan_status(item.id)
                    console.log(if_love.data.data[0])
                    let type = if_love.data.data[0]

                    if (type == 'null') {
                        item.love_type = false
                        item.unlove_type = false
                    } else if (type == 'false') {
                        item.love_type = false
                        item.unlove_type = true
                    } else {
                        item.love_type = true
                        item.unlove_type = false
                    }

                })
                setTimeout(() => {

                    item.replies = this.deteleObject(item.replies)

                }, 500)




            }

            item.date = util.formatTime_1(new Date(item.date))
        })



        this.data.pl_values[index] = res.data.data[0]

        setTimeout(() => {
            this.setData({
                pl_values: this.data.pl_values
            })
        }, 500)
    },


    //生成闭包
    get_huifu_list() {
        let page = 1
        let size = 5

        let total = 50
        return (id, type, index) => {

            //向上取整

            if (Math.ceil(total / size) >= page) {
                getReplyList({
                    "commentId": id,
                    "page": page,
                    "pageSize": size,
                    "byType": type
                }).then(res => {
                    total = res.data.data.total - 1

                    let type = null


                    res.data.data.list.forEach(item_1 => {
                        item_1.fromUserNickname = this.uncodeUtf16(item_1.fromUserNickname)
                        item_1.toUserNickname = this.uncodeUtf16(item_1.toUserNickname)
                        item_1.content = JSON.parse(item_1.content)
                        item_1.id_1 = item_1.id
                        item_1.id = id
                        item_1.date = util.formatTime_1(new Date(item_1.date))
                        item_1.ifPublic = 0

                        this.get_dianzan_status(item_1.id_1).then(res => {

                            type = res.data.data[0]
                            if (type == 'null') {
                                item_1.love_type = false
                                item_1.unlove_type = false
                            } else if (type == 'false') {
                                item_1.love_type = false
                                item_1.unlove_type = true
                            } else {
                                item_1.love_type = true
                                item_1.unlove_type = false
                            }

                        })

                    })


                    this.data.pl_values[index].replyCount = this.data.pl_values[index].replyCount - size

                    this.data.pl_values[index].replies = [...this.data.pl_values[index].replies, ...res.data.data.list]





                    setTimeout(() => {
                        this.data.pl_values[index].replies = this.deteleObject(this.data.pl_values[index].replies)
                        this.setData({
                            pl_values: this.data.pl_values
                        })

                    }, 200)


                })
                page++





            } else {


                //消息提示没有更多啦
                // wx.showToast({
                //     title: '没有更多了',
                //     icon: 'none',
                //     duration: 2000
                // })

                //收起评论
                page = 1
                this.data.pl_values[index].replyCount = this.data.pl_values[index].num + 1
                this.data.pl_values[index].replies = []

                this.setData({
                    pl_values: this.data.pl_values
                })

                // getReplyList({
                //     "commentId": id,
                //     "page": page,
                //     "pageSize": size,
                //     "byType": type
                // }).then(res => {
                //     total = res.data.data.total - 1

                //     let type = null


                //     res.data.data.list.forEach(item_1 => {
                //         item_1.fromUserNickname = this.uncodeUtf16(item_1.fromUserNickname)
                //         item_1.toUserNickname = this.uncodeUtf16(item_1.toUserNickname)
                //         item_1.content = JSON.parse(item_1.content)
                //         item_1.id_1 = item_1.id
                //         item_1.id = id
                //         item_1.date = util.formatTime_1(new Date(item_1.date))
                //         item_1.ifPublic = 0

                //         this.get_dianzan_status(item_1.id_1).then(res => {

                //             type = res.data.data[0]
                //             if (type == 'null') {
                //                 item_1.love_type = false
                //                 item_1.unlove_type = false
                //             } else if (type == 'false') {
                //                 item_1.love_type = false
                //                 item_1.unlove_type = true
                //             } else {
                //                 item_1.love_type = true
                //                 item_1.unlove_type = false
                //             }
                //               
                //         })

                //     })


                //     this.data.pl_values[index].replyCount = this.data.pl_values[index].replyCount - size

                //     this.data.pl_values[index].replies = [...this.data.pl_values[index].replies, ...res.data.data.list]





                //     setTimeout(() => {
                //         this.data.pl_values[index].replies = this.deteleObject(this.data.pl_values[index].replies)
                //         this.setData({
                //             pl_values: this.data.pl_values
                //         })

                //     }, 200)


                // })



            }



        }
    },

    //展开评论
    zhankai(e) {

        let index = e.currentTarget.dataset.index_1
        this.data.index = index
        let value = this.data.pl_values[index]

        let id = e.currentTarget.dataset.value.id
        this.data.huifu_id = id


        this.data.get_huifu_list_1(id, 0, index)

        setTimeout(() => {
            this.getHeight(id)
        }, 2000)

    },

    //点赞
    dianzhan(e) {

        let data = e.currentTarget.dataset.data_1
        let index = e.currentTarget.dataset.type
        let index_1 = e.currentTarget.dataset.type_1
        let value = e.currentTarget.dataset.value
        let type = e.currentTarget.dataset.dain_type

        //点赞成功改变样式
        if (value.love_type == false) {
            value.unlove_type ? value.unlove_type = false : ''
            value.love_type = true
            value.ip = parseInt(value.ip) + 1
            //点赞成功改变样式
        } else {
            value.love_type = false
            value.ip = parseInt(value.ip) - 1
        }
        let messtext = ''
        wx.vibrateShort({
            type:'heavy',
            success: res => {
              console.log(res)
            }
          })
        if (type == 1) {
           
            data[index] = value
            messtext = '点赞了你的评论'
            this.setData({
                pl_values: data
            })
            this.app.dianzan({
                "openId": wx.getStorageSync('openid'),
                "type": "0",
                "typeMessageId": value.id,
                "upOrDown": true
            })


        } else {
            this.data.pl_values[index_1].replies[index] = value
            messtext = '点赞了你的回复'
            this.setData({
                pl_values: this.data.pl_values
            })
            this.app.dianzan({
                "openId": wx.getStorageSync('openid'),
                "type": type,
                "typeMessageId": value.id_1,
                "upOrDown": true
            })
        }



        let data_1 = {
            access_token: "accwss_token",
            touser: value.retweets || value.fromUserId,
            template_id: "A2xUwOpJv6EJWXd9alXNG964WlB7IMrVAT9kY9oc_M8",
            page: "/pages/index/index",
            miniprogram_state: "formal",
            lang: "zh_CN",
            data: {
                name1: {
                    value: this.data.wx_info.nickName
                },
                thing2: {
                    value: "FFLOVE"
                },
                thing3: {
                    value: messtext
                },
                date4: {
                    //当前时间
                    value: util.formatTime(new Date())

                }
            }
        }
        if (data_1.touser != wx.getStorageSync('openid')) {
            this.app.send_message(data_1)
        }











    },

    undainzhan(e) {

        let data = e.currentTarget.dataset.data_1
        let index = e.currentTarget.dataset.type
        let index_1 = e.currentTarget.dataset.type_1
        let value = e.currentTarget.dataset.value
        let type = e.currentTarget.dataset.dain_type
        if (value.unlove_type == false) {
            value.love_type ? value.love_type = false : ''
            value.unlove_type = true
            value.ip = parseInt(value.ip) - 1


            //点赞成功改变样式
        } else {
            value.unlove_type = false
            value.ip = parseInt(value.ip) + 1
        }
        if (type == 1) {
            data[index] = value
            this.setData({
                pl_values: data
            })
        } else {
            this.data.pl_values[index_1].replies[index] = value
            this.setData({
                pl_values: this.data.pl_values
            })
        }
        this.app.dianzan({
            "openId": wx.getStorageSync('openid'),
            "type": type,
            "typeMessageId": type == 1 ? value.id : value.id_1,
            "upOrDown": false
        })
    },

    //点赞回复
    dianzhan_pl(e) {




    },

    //删除留言
    del_liuyan() {

        Dialog.confirm({
                title: '提示',
                message: '确定要删除您的留言吗？',
            })
            .then(() => {


                deleteMessage({
                    openId: wx.getStorageSync('openid'),
                    leaveMessageId: this.data.list.id
                }).then(res => {
                    if (res.statusCode == 200) {


                        wx.showToast({
                            title: '删除成功',
                            icon: 'success',
                            duration: 1000
                        })
                        //删除列表
                        wx.navigateTo({
                            url: '/pages/liuyan/liuyan'
                        })



                    } else {
                        wx.showToast({
                            title: '删除失败',
                            icon: 'none',
                            duration: 1000
                        })


                    }

                })
            })
            .catch(() => {
                // on cancel
            });
    },

    //点赞留言
    like_ly() {
        let pages = getCurrentPages(); // 当前页的数据
        let prevPage = pages[pages.length - 2]; // 上一页的数据
        let value = this.data.list

        if (value.love_type) { //取消点赞

            this.app.dianzan({
                "openId": wx.getStorageSync('openid'),
                "type": "0",
                "typeMessageId": value.id,
                "upOrDown": true
            })
            this.data.list.love_type = false
            prevPage.data.pl_data[this.data.index].love_type = false
            prevPage.data.pl_data[this.data.index].ip--
            prevPage.setData({
                pl_data: prevPage.data.pl_data
            })

            this.setData({
                list: this.data.list
            })
        } else if (!value.love_type) {

            let messtext = '点赞了你的留言'
            this.app.dianzan({
                "openId": wx.getStorageSync('openid'),
                "type": "0",
                "typeMessageId": value.id,
                "upOrDown": true
            })
            this.data.list.love_type = true
            this.setData({
                list: this.data.list
            })
            let data = {
                access_token: "accwss_token",
                touser: value.retweets,
                template_id: "A2xUwOpJv6EJWXd9alXNG964WlB7IMrVAT9kY9oc_M8",
                page: "/pages/index/index",
                miniprogram_state: "formal",
                lang: "zh_CN",
                data: {
                    name1: {
                        value: this.data.wx_info.nickName
                    },
                    thing2: {
                        value: "FFLOVE"
                    },
                    thing3: {
                        value: messtext
                    },
                    date4: {
                        //当前时间
                        value: util.formatTime(new Date())

                    }
                }
            }

            if (data.touser != wx.getStorageSync('openid')) {
                this.app.send_message(data)
            }

            prevPage.data.pl_data[this.data.index].love_type = true
            prevPage.data.pl_data[this.data.index].ip++
            prevPage.setData({
                pl_data: prevPage.data.pl_data
            })



        }


        /** prevPageValue 是上一页你想被携带过去的数据 */
        console.log(prevPage.data)

    },



    //预览图片
    tab(e) {


        let url = e.currentTarget.dataset.url.url
        let arr = []
        arr.push(url)


        wx.previewImage({
            current: url,
            urls: arr
        })
    },

    //打开评论
    pl_open(e) {

        let type = e.currentTarget.dataset.type
        // this.data.pl_type = '2'
        if (type == 1) {
            this.setData({

                emol_open_is: 'true'
            })
        }
        this.data.sendopenid = this.data.list.retweets
        this.setData({
            text_type: 'true',
            pl_type: '2',

        })
    },
    //关闭评论
    off_pl() {
        this.setData({
            text_type: 'false',
            is_emol: false,
            emol_open_is: 'false'
        })
    },
    //页面滚动
    touchStart(e) {

        //添加定时器
        this.data.timer = setTimeout(() => {
            this.setData({
                is_foot: false
            })
        }, 80);



    },
    //页面停止滚动

    touchEnd() {
        this.setData({
            is_foot: true
        })
        clearTimeout(this.data.timer);


    },
    tou_type() {


        this.setData({
            type: this.data.type == 'NEW' ? 'HOT' : 'NEW',
            w: this.data.w == '0' ? '70' : '0',
        })
    },

    //转换表情
    uncodeUtf16(str) {
        var reg = /\&#.*?;/g;
        var result = str.replace(reg, function (char) {
            var H, L, code;
            if (char.length == 9) {
                code = parseInt(char.match(/[0-9]+/g));
                H = Math.floor((code - 0x10000) / 0x400) + 0xD800;
                L = (code - 0x10000) % 0x400 + 0xDC00;
                return unescape("%u" + H.toString(16) + "%u" + L.toString(16));
            } else {
                return char;
            }
        });
        return result;
    },
    //去掉相同对象
    deteleObject(obj) {
        var uniques = [];
        var stringify = {};
        for (var i = 0; i < obj.length; i++) {
            var keys = Object.keys(obj[i]);
            keys.sort(function (a, b) {
                return (Number(a) - Number(b));
            });
            var str = '';
            for (var j = 0; j < keys.length; j++) {
                str += JSON.stringify(keys[j]);
                str += JSON.stringify(obj[i][keys[j]]);
            }
            if (!stringify.hasOwnProperty(str)) {
                uniques.push(obj[i]);
                stringify[str] = true;
            }
        }
        uniques = uniques;
        return uniques;
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        watch.setWatcher(this);
        get_show().then(res => {
            if (res.data.password == app.getVersion()) {
                this.data.type_1 = res.data.stuNumber
             
              }else{
                this.data.type_1 = 'false'
              }
            this.setData({
                type_1: this.data.type_1
            })
        })
        options=JSON.parse(decodeURIComponent(options.list))
        console.log(options)
        // options=JSON.stringify(options)
        this.data.index = options.index

        this.data.get_huifu_list_1 = this.get_huifu_list()


        this.app = getApp()

        this.data.wx_info = wx.getStorageSync('wx_user_info')
        this.data.list = options

        this.data.page = 1
        this.get_pl_list(this.data.page, 6, 1, 1)
        this.setData({
            list: this.data.list,
            openid: wx.getStorageSync('openid'),
            emol_list: this.app.globalData.getEmolist
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    async onShow() {


    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function (e) {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        wx.vibrateShort({
            type:'heavy',
            success: res => {
              console.log(res)
            }
          })
        this.data.get_huifu_list_1 = this.get_huifu_list()
        this.data.pl_values = []
        this.data.page = 1
        this.data.num_if = false
        this.get_pl_list(this.data.page, 6, 1, 1)

        //消息提示刷新成功
        wx.showToast({
            title: '刷新成功',
            icon: 'none',
            duration: 1000
        })

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

        setTimeout(() => {
            if (this.data.list.replyCount / 6 >= this.data.page) {

                this.data.page++

                this.get_pl_list(this.data.page, 6, 1, 1)


            } else {
                wx.showToast({
                    title: '没有更多了',
                    icon: 'none',
                    duration: 1000
                })
            }
        }, 500)


    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})